<?php
/*
* Copyright 2010-2013 Eloy Asensio Madrigal. All rights reserved.
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
* 
* You should have received a copy of the GNU General Public License along with this program.
* If not, see http://www.opensource.org/licenses/gpl-3.0.html
*/
class Arduino
{
	private static $instance = null;
	private $fp = null;
	private $filename = '/dev/ttyACM0';
	private static $mode = 'w+';
	private $size = 1;
	
	public function __construct()
	{
		$this->filename = '/dev/ttyACM0';
		$this->mode = 'w+';
		$this->fp =fopen($this->filename, $this->mode);
	}
	public function __destruct()
	{
	        fclose($fp);
	}

	public static function singleton()
	{
		if( self::$instance == null )
		{
			self::$instance = new self();
		}
		return self::$instance;
	}
	
	public function fwrite($text)
	{
		fwrite($this->fp,$text);
		echo fread($this->fp, $this->size);
	}
	
	public function fread($_size)
	{
		if( isset($_size) ) $r_size = $_size;
		else $r_size = $this->size;
		$var = fread($this->fp, $this->size);
	}
}
?>